#ifndef __FSTORAGE_H_
#define __FSTORAGE_H_

#include "fboot.h"

typedef struct fstorage_interface
{
	size_t 				         type;
	size_t 				         read_pos;
	size_t 				         write_pos;
	size_t 				         data_max;
	uint32_t 				       openflags;
	int                    file_fd;
	void *                 fal_part;
	char                   name[256];
}fstorage_interface_t;

#define FSTORAGE_READ              0x0000U
#define FSTORAGE_WRITE             0x0001U
#define FSTORAGE_READWRITE         0x0002U

#define FSTORAGE_CHECK_EXIST       0x0010U
#define FSTORAGE_CREATE_NEW        0x0020U


fstorage_interface_t * fstorage_fal_open(const char* fal_part_name, uint32_t openflags);

void fstorage_fal_close(fstorage_interface_t *interface);

#if (FBOOT_USING_FILESYSTEM == 1)	

fstorage_interface_t * fstorage_fs_open(const char* fs_file_path, uint32_t openflags);

void fstorage_fs_close(fstorage_interface_t *interface);

#endif


size_t fstorage_read(fstorage_interface_t *interface, size_t offset, void* buffer, size_t len);

size_t fstorage_write(fstorage_interface_t *interface, size_t offset, const void* buffer, size_t len);

size_t fstorage_erase(fstorage_interface_t *interface, size_t offset, size_t len);

size_t fstorage_size(fstorage_interface_t *interface);

#endif

